package leetcode;


import java.util.Arrays;

/**
 * @author niann
 * @description TODO https://leetcode.cn/problems/move-zeroes/?envType=study-plan-v2&envId=top-100-liked
 * @since 2024/11/14 18:37
 **/
public class LeetCode283 {
    class Solution {
        public void moveZeroes(int[] nums) {
            int slow = 0;
            int fast = 0;

            while (fast < nums.length) {
                if (nums[fast]!= 0) {
                    // 将非零元素与慢指针指向的位置交换
                    int temp = nums[slow];
                    nums[slow] = nums[fast];
                    nums[fast] = temp;

                    slow++;
                }
                fast++;
            }
        }
    }
    public static void main(String[] args) {
        Solution solution = new LeetCode283().new Solution();
        solution.moveZeroes(new int[]{0,0,1});
    }

}
